home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tcl / dist6.3 / tests / if.test < prev    next >
Encoding:
Text File  |  1991-08-20  |  4.4 KB  |  171 lines

  1. # Commands covered:  if
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/if.test,v 1.3 91/08/20 14:19:03 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test if-1.1 {taking proper branch} {
  21.     set a {}
  22.     if 0 {set a 1} else {set a 2}
  23.     set a
  24. } 2
  25. test if-1.2 {taking proper branch} {
  26.     set a {}
  27.     if 1 {set a 1} else {set a 2}
  28.     set a
  29. } 1
  30. test if-1.3 {taking proper branch} {
  31.     set a {}
  32.     if 1<2 {set a 1}
  33.     set a
  34. } 1
  35. test if-1.4 {taking proper branch} {
  36.     set a {}
  37.     if 1>2 {set a 1}
  38.     set a
  39. } {}
  40. test if-1.4 {taking proper branch} {
  41.     set a {}
  42.     if 1>2 {set a 1} else {}
  43.     set a
  44. } {}
  45.  
  46. test if-2.1 {optional then-else args} {
  47.     set a 44
  48.     if 1==3 then {set a 1} else {set a 2}
  49.     set a
  50. } 2
  51. test if-2.2 {optional then-else args} {
  52.     set a 44
  53.     if 1!=3 then {set a 1} else {set a 2}
  54.     set a
  55. } 1
  56. test if-2.3 {optional then-else args} {
  57.     set a 44
  58.     if 1==3 {set a 1} else {set a 2}
  59.     set a
  60. } 2
  61. test if-2.4 {optional then-else args} {
  62.     set a 44
  63.     if 1!=3 {set a 1} else {set a 2}
  64.     set a
  65. } 1
  66. test if-2.5 {optional then-else args} {
  67.     set a 44
  68.     if 1==3 then {set a 1} {set a 2}
  69.     set a
  70. } 2
  71. test if-2.6 {optional then-else args} {
  72.     set a 44
  73.     if 1!=3 then {set a 1} {set a 2}
  74.     set a
  75. } 1
  76. test if-2.7 {optional then-else args} {
  77.     set a 44
  78.     if 1==3 {set a 1} {set a 2}
  79.     set a
  80. } 2
  81. test if-2.8 {optional then-else args} {
  82.     set a 44
  83.     if 1!=3 {set a 1} {set a 2}
  84.     set a
  85. } 1
  86. test if-2.9 {optional then-else args} {
  87.     set a 44
  88.     if 1==3 t {set a 1} e {set a 2}
  89.     set a
  90. } 2
  91.  
  92. test if-3.1 {error conditions} {
  93.     catch {if 2}
  94. } 1
  95. test if-3.2 {error conditions} {
  96.     catch {if 2} msg
  97.     set msg
  98. } {wrong # args: should be "if bool ?then? command ?else? ?command?"}
  99. test if-3.3 {error conditions} {
  100.     catch {if 1 then}
  101. } 1
  102. test if-3.4 {error conditions} {
  103.     catch {if 1 then} msg
  104.     set msg
  105. } {wrong # args: should be "if bool ?then? command ?else? ?command?"}
  106. test if-3.5 {error conditions} {
  107.     catch {if 1 {set a b} else}
  108. } 1
  109. test if-3.6 {error conditions} {
  110.     catch {if 1 {set a b} else} msg
  111.     set msg
  112. } {wrong # args: should be "if bool ?then? command ?else? ?command?"}
  113. test if-3.7 {error conditions} {
  114.     catch {if {[error "error in condition"]} foo}
  115. } 1
  116. test if-3.8 {error conditions} {
  117.     catch {if {[error "error in condition"]} foo} msg
  118.     set msg
  119. } {error in condition}
  120. test if-3.9 {error conditions} {
  121.     catch {if {[error "error in condition"]} foo} msg
  122.     set errorInfo
  123. } {error in condition
  124.     while executing
  125. "error "error in condition""
  126.     ("if" test line 1)
  127.     invoked from within
  128. "if {[error "error in condition"]} foo"}
  129. test if-3.10 {error conditions} {
  130.     catch {if 1 then {error "error in then clause"}}
  131. } 1
  132. test if-3.11 {error conditions} {
  133.     catch {if 1 then {error "error in then clause"}} msg
  134.     set msg
  135. } {error in then clause}
  136. test if-3.12 {error conditions} {
  137.     catch {if 1 then {error "error in then clause"}} msg
  138.     set errorInfo
  139. } {error in then clause
  140.     while executing
  141. "error "error in then clause""
  142.     ("then" clause line 1)
  143.     invoked from within
  144. "if 1 then {error "error in then clause"}"}
  145. test if-3.13 {error conditions} {
  146.     catch {if 0 {} {error "error in else clause"}}
  147. } 1
  148. test if-3.14 {error conditions} {
  149.     catch {if 0 {} {error "error in else clause"}} msg
  150.     set msg
  151. } {error in else clause}
  152. test if-3.15 {error conditions} {
  153.     catch {if 0 {} {error "error in else clause"}} msg
  154.     set errorInfo
  155. } {error in else clause
  156.     while executing
  157. "error "error in else clause""
  158.     ("else" clause line 1)
  159.     invoked from within
  160. "if 0 {} {error "error in else clause"}"}
  161.  
  162. test if-4.1 {return value} {
  163.     if 1 then {set a 22; format abc}
  164. } abc
  165. test if-4.2 {return value} {
  166.     if 0 then {set a 22; format abc} else {format def}
  167. } def
  168. test if-4.3 {return value} {
  169.     if 0 then {set a 22; format abc}
  170. } {}
  171.